package com.itboye.shop.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.itboye.shop.R;
import com.itboye.shop.bean.JiaoYiJiLuBean;
import com.itboye.shop.util.helper.utils.TimeFormat;

import java.util.List;

/**
 * 交易记录
 */
public class JiaoYiJiLuAdapter extends android.widget.BaseAdapter {

    List<JiaoYiJiLuBean.ListEntity> list;
    Context context;

    public JiaoYiJiLuAdapter(Context context, List<JiaoYiJiLuBean.ListEntity> list){
        this.list=list;
        this.context=context;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public Object getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    @Override
    public View getView(int position, View view, ViewGroup parent) {
        ViewHolder holder=null;
        if(view==null){
            holder=new ViewHolder();
            view= LayoutInflater.from(context).inflate(R.layout.item_jiao_yi_ji_lu,null);
            holder.item_tixian_type= (TextView) view.findViewById(R.id.item_tixian_type);
            holder.item_tixian_yue= (TextView) view.findViewById(R.id.item_tixian_yue);
            holder.item_tixian_time= (TextView) view.findViewById(R.id.item_tixian_time);
            holder.item_tixian_money= (TextView) view.findViewById(R.id.item_tixian_money);

            view.setTag(holder);
        }else{
            holder= (ViewHolder) view.getTag();
        }
        holder.item_tixian_type.setText(list.get(position).getReason());
        holder.item_tixian_time.setText(TimeFormat.DateFormat(list.get(position).getCreate_time()+""));
        holder.item_tixian_yue.setText("余额:"+ Double.parseDouble(list.get(position).getAfter_money()+"")/100);
      //  holder.item_tixian_money.setText("￥:"+Double.parseDouble(list.get(position).getPlus()+"")/100);
        if(list.get(position).getMinus()==0){
            holder.item_tixian_money.setText("+"+ Double.parseDouble(list.get(position).getPlus()+"")/100);
        }else{
            holder.item_tixian_money.setText("-"+ Double.parseDouble(list.get(position).getMinus()+"")/100);
        }

        return view;
    }

    class ViewHolder{
        TextView item_tixian_type,item_tixian_yue,item_tixian_time,item_tixian_money;
    }
}
